package com.org.gundutubruk;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListRekap extends Activity{
	LinearLayout kontainer;
	public static Player[] paraPemain;
	public static int[] jumGundu;
	int apatarbase = R.drawable.apatarmini0;
	TextView judul;
	boolean isMultiplayer;
	
	@Override
	public void onBackPressed(){
		nextAct();
	}
	
	private void nextAct() {
		if(!isMultiplayer) {//jika tidak multiplayer, alihkan ke menu utama, jika tidak cukup hentikan activity ini
			this.startActivity(new Intent("android.intent.action.MENUUTAMA"));
			overridePendingTransition(R.anim.fade, R.anim.hold);
		}
		this.finish();
	}

	public boolean onTouchEvent(MotionEvent event){
		nextAct();
		return false;
	}
	
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.list_rekap);
		//cek apakah list rekap ini dijalankan dengan mode multiplayer
		//soalnya kalo multiplayer, akan dibalikkan lagi ke room
		Bundle b = getIntent().getExtras();
		if(b!=null) {
			isMultiplayer = b.getBoolean("isMultiplayer",false);
		}
		castItem();		
	}
	private void castItem() {
		kontainer=(LinearLayout)findViewById(R.id.kontainer);
		kontainer.setOrientation(LinearLayout.VERTICAL);
		judul = new TextView(this);
		judul.setBackgroundResource(R.drawable.statistik);
		judul.setTextSize(30);
		kontainer.addView(judul);
		for(int i=0;i<paraPemain.length;i++){
			LinearLayout item = new LinearLayout(this);
			TextView blank=new TextView(this);
			TextView blank2=new TextView(this);
			TextView blank3=new TextView(this);
			blank.setText("     ");
			blank2.setText("     ");
			TextView keterangan = new TextView(this);
			keterangan.setTextSize(24);
			keterangan.setTextColor(Color.YELLOW);
			Log.d("asd", "para pemain nama = "+paraPemain[i].name);
			Log.d("asd", "jum gundu = "+jumGundu[i]);
			keterangan.setText("\n     "+paraPemain[i].name+" x "+jumGundu[i]);
			keterangan.setGravity(Gravity.CENTER_VERTICAL);
			ImageView apatar = new ImageView(this);
			apatar.setImageResource(apatarbase+paraPemain[i].avatar);
			apatar.setScaleType(ScaleType.FIT_XY);
			item.setOrientation(LinearLayout.HORIZONTAL);
			item.addView(blank2);
			item.addView(apatar);
			item.addView(keterangan);
			kontainer.addView(blank);			
			kontainer.addView(item);
			kontainer.addView(blank3);
		}
	}
}
